<?php
namespace Framework\View;

class View
{
	public $name;

    public $defaultExtension = 'php';

	public function render($view, array $params=[])
	{

        if (substr($view, 0, 4) === '@yii') {
            $templateFile = str_replace('@yii', dirname(dirname(__DIR__)) . '/vendor/yiisoft/yii2', $view);

        }else{
			//找到模板文件位置
			$templatePath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'templates' ;
			$templateFile = $templatePath . DIRECTORY_SEPARATOR . $view . '.' . $this->defaultExtension;

        }

		return $this->renderFile($templateFile, $params);
	}

	public function renderFile($viewFile, array $params=[])
	{
        ob_start();
        ob_implicit_flush(false);

        extract($params);
        require $viewFile;

        return ob_get_clean();
	}
}